package leetcode.code0714;

public class Solution {
	public int maxProfit(int[] prices, int fee) {
		int len = prices.length;
		int[] h = new int[len];
		int[] n = new int[len];
		h[0] = -prices[0];
		for (int i = 1; i < n.length; i++) {
			int p = prices[i];
			h[i] = Math.max(h[i - 1], n[i - 1] - p);
			n[i] = Math.max(n[i - 1], h[i - 1] + p - fee);
		}
		return n[len - 1];
	}
}
